<template>
<div class="list">
      <van-list
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="onLoad"
      >
        <div v-for="(item, index) in list" :key="index">
          <h4>{{ item.name }}</h4>
          <div class="singers">
            <span v-for="(singer, index) in item.singer" :key="singer.id">
              {{ singer.name }}
              <span v-show="index != item.singer.length - 1">/</span>
            </span>            
            <span v-show="item.album">
              <span>.</span>
              <span>{{ item.album }}</span>              
            </span>

          </div>
        </div>
      </van-list>
    </div>
</template>

<script>
export default {
    props: ["singerId"],
    data() {
        return {
            list: [],  //vant的list列表数据
            loading: false,
            finished: false,
            page: 1,  //获取api数据的页码
            
        };
    },

    // created(){
    //     this.getData(this.singerId,1,10)
    // },
    methods:{
        getData() {
            this.$request(
                "get",
                "/singer/songs?singermid=" + this.singerId + "&page=" + this.page + "&num=30"
                ).then((res) => {
                    this.list = this.list.concat(res.data.list);
                    this.loading = false;
                    this.page++;
                    if (res.data.list.length == 0) {
                        this.finished = true;
                    }
                });           
        },
        onLoad() {
            setTimeout (() => {
                this.getData(); //调用获取分页数据的方法
                this.loading = true;  //正在加载
            }, 1000);
        },
    },
};
</script>

<style scoped>
.list {
  margin: 0 1rem;
}
.list h3 {
  text-align: left;
  font-size: 1rem;
}
.singer {
  text-align: left;
}
.singer span {
  font-size: 0.8rem;
  color: rgb(160, 160, 190);
}
.singer > span:nth-last-child(1) > span:nth-child(1) {
  color: red;
  font-weight: 900;
  padding: 0 0.5rem;
}
</style>
